//
//  FANTextView.m
//  Weibo - OC
//
//  Created by user on 16/4/26.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANTextView.h"

//#warning 宏定义一定要放到 导入头文件的 上面, 会影响编译

//define this constant if you want to use Masonry without the 'mas_' prefix

#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax

#define MAS_SHORTHAND_GLOBALS

#import <Masonry/Masonry.h>

@interface FANTextView ()

@property (nonatomic, strong) UILabel *label;

@end

@implementation FANTextView

- (void)setPlaceHolder:(NSString *)placeHolder{
    
    _placeHolder = placeHolder;
    
    self.label.text = placeHolder;
    
}

- (void)setFont:(UIFont *)font{
    
    [super setFont:font];
    
    self.label.font = self.font;

}

- (UILabel *)label{
    
    if (!_label) {
        
        _label = [[UILabel alloc] init];
        
        _label.alpha = 0.8;
        
        _label.text = @"下雨天音乐与辣条更配哟~~";
        
        _label.textColor = [UIColor darkGrayColor];
        
        _label.numberOfLines = 0;
        
        _label.font = [UIFont systemFontOfSize:14];
    }
    
    return _label;
}

- (instancetype)initWithFrame:(CGRect)frame textContainer:(NSTextContainer *)textContainer{
    
    if (self = [super initWithFrame:frame textContainer:textContainer]) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    [self addSubview:self.label];
    
    [self.label makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self).offset(8);
        
        make.leading.equalTo(self).offset(5);
        
        make.width.equalTo(self).offset(-10);
        
    }];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textViewChange) name:UITextViewTextDidChangeNotification object:nil];
}

- (void)textViewChange{
    
    self.label.hidden = self.hasText;
}

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
